﻿//------------------------------------------------------------------------------
// 创建标识: Copyright (C) 2010 Socansoft.com 版权所有
// 创建描述: SocanCode代码生成器 V4.3.3.6 自动创建于 2010/4/21 17:07:35
//
// 功能描述: 
//
// 修改标识: 
// 修改描述: 
//------------------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace OPMS_IBS_2.SqlServerDAL
{
	/// <summary>
	/// 数据访问类 TimeTableDetail
	/// </summary>
	public class TimeTableDetail : DALHelper
	{
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(OPMS_IBS_2.Model.TimeTableDetail model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("INSERT INTO TimeTableDetail(");
            strSql.Append("OwnTimeTable,RowNUM,ColNUM,Content,OwnToken,OwnPart)");
			strSql.Append(" VALUES (");
            strSql.Append("@in_OwnTimeTable,@in_RowNUM,@in_ColNUM,@in_Content,@in_OwnToken,@in_OwnPart)");
			DbParameter[] cmdParms = {
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnTimeTable", DbType.Guid, model.OwnTimeTable),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_RowNUM", DbType.Int32, model.RowNUM),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ColNUM", DbType.Int32, model.ColNUM),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_Content", DbType.AnsiString, model.Content),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnToken", DbType.Guid, model.OwnToken),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnPart", DbType.Int32, model.OwnPart)};

			return OPMS_IBS_2Helper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public int Update(OPMS_IBS_2.Model.TimeTableDetail model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("UPDATE TimeTableDetail SET ");
			strSql.Append("OwnTimeTable=@in_OwnTimeTable,");
			strSql.Append("RowNUM=@in_RowNUM,");
			strSql.Append("ColNUM=@in_ColNUM,");
			strSql.Append("Content=@in_Content,");
			strSql.Append("OwnToken=@in_OwnToken,");
			strSql.Append("OwnPart=@in_OwnPart");
			strSql.Append(" WHERE ID=@in_ID");
			DbParameter[] cmdParms = {
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnTimeTable", DbType.Guid, model.OwnTimeTable),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_RowNUM", DbType.Int32, model.RowNUM),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ColNUM", DbType.Int32, model.ColNUM),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_Content", DbType.AnsiString, model.Content),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnToken", DbType.Guid, model.OwnToken),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_OwnPart", DbType.Int32, model.OwnPart),
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ID", DbType.Guid, model.ID)};
			return OPMS_IBS_2Helper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public int Delete(Guid ID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("DELETE FROM TimeTableDetail ");
			strSql.Append(" WHERE ID=@in_ID");
			DbParameter[] cmdParms = {
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ID", DbType.Guid, ID)};

			return OPMS_IBS_2Helper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid ID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("SELECT COUNT(1) FROM TimeTableDetail");
			strSql.Append(" WHERE ID=@in_ID");
			DbParameter[] cmdParms = {
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ID", DbType.Guid, ID)};

			object obj = OPMS_IBS_2Helper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
			return OPMS_IBS_2Helper.GetInt(obj) > 0;
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public OPMS_IBS_2.Model.TimeTableDetail GetModel(Guid ID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("SELECT * FROM TimeTableDetail ");
			strSql.Append(" WHERE ID=@in_ID");
			DbParameter[] cmdParms = {
				OPMS_IBS_2Helper.CreateInDbParameter("@in_ID", DbType.Guid, ID)};

			OPMS_IBS_2.Model.TimeTableDetail model = null;
			using (DbDataReader dr = OPMS_IBS_2Helper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
			{
				while (dr.Read())
				{
					model = GetModel(dr);
				}
				return model;
			}
		}

		/// <summary>
		/// 获取泛型数据列表
		/// </summary>
		public List<OPMS_IBS_2.Model.TimeTableDetail> GetList()
		{
			StringBuilder strSql = new StringBuilder("SELECT * FROM TimeTableDetail");
			using (DbDataReader dr = OPMS_IBS_2Helper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
			{
				List<OPMS_IBS_2.Model.TimeTableDetail> lst = GetList(dr);
				return lst;
			}
		}

		/// <summary>
		/// 得到数据条数
		/// </summary>
		public int GetCount(string condition)
		{
			return OPMS_IBS_2Helper.GetCount("TimeTableDetail", condition);
		}

		/// <summary>
		/// 分页获取泛型数据列表
		/// </summary>
		public List<OPMS_IBS_2.Model.TimeTableDetail> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
		{
			using (DbDataReader dr = OPMS_IBS_2Helper.GetPageList("TimeTableDetail", pageSize, pageIndex, fldSort, fldDir, condition))
			{
				List<OPMS_IBS_2.Model.TimeTableDetail> lst = GetList(dr);
				return lst;
			}
		}

		#region -------- 私有方法，通常情况下无需修改 --------

		/// <summary>
		/// 由一行数据得到一个实体
		/// </summary>
		private OPMS_IBS_2.Model.TimeTableDetail GetModel(DbDataReader dr)
		{
			OPMS_IBS_2.Model.TimeTableDetail model = new OPMS_IBS_2.Model.TimeTableDetail();
			model.ID = OPMS_IBS_2Helper.GetGuid(dr["ID"]);
			model.OwnTimeTable = OPMS_IBS_2Helper.GetGuid(dr["OwnTimeTable"]);
			model.RowNUM = OPMS_IBS_2Helper.GetInt(dr["RowNUM"]);
			model.ColNUM = OPMS_IBS_2Helper.GetInt(dr["ColNUM"]);
			model.Content = OPMS_IBS_2Helper.GetString(dr["Content"]);
			model.OwnToken = OPMS_IBS_2Helper.GetGuid(dr["OwnToken"]);
			model.OwnPart = OPMS_IBS_2Helper.GetInt(dr["OwnPart"]);
			return model;
		}

		/// <summary>
		/// 由DbDataReader得到泛型数据列表
		/// </summary>
		private List<OPMS_IBS_2.Model.TimeTableDetail> GetList(DbDataReader dr)
		{
			List<OPMS_IBS_2.Model.TimeTableDetail> lst = new List<OPMS_IBS_2.Model.TimeTableDetail>();
			while (dr.Read())
			{
				lst.Add(GetModel(dr));
			}
			return lst;
		}

		#endregion
	}
}
